export default {
  // inserted：被绑定元素插入父节点时调用 (仅保证父节点存在，但不一定已被插入文档中)。
  inserted (el, binding) {
    const { value } = binding
    const allPermission = '*:*:*'
    const userInfo = localStorage.getItem('Standard__User-Info')

    const permissions = [JSON.parse(userInfo).value.isManager]

    if (value && value instanceof Array && value.length > 0) {
      const permissionFlag = value
      const hasPermissions = permissions.some(permission => {
        return allPermission === permission || permissionFlag.includes(permission)
      })
      if (!hasPermissions) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    } else {
      el.parentNode && el.parentNode.removeChild(el)
      throw new Error(`请设置操作权限标签`)
    }
  }
}
